<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Transformers\NewsTransformer;
use App\Http\Controllers\Transformers\SingleNewsTransformer;
use App\Model\News;
use Illuminate\Http\Request;

class NewsController extends Controller
{
//获得单挑数据的方法
    public function singleNews($id){
        $news=News::find($id);
        return $this->response->item($news,new NewsTransformer());
    }
//    获得全部数据的方法
    public function news($classify=0){
        if ($classify){
            $news = News::where('classify_id',$classify)->get();
        }else{
            //返回所有的新闻数据
            $news = News::get();
        }
//        $news=News::get();
//        dd($news);
        return $this->response->collection($news,new NewsTransformer());
    }
}
